<!-- 我的经营信息 -->
<template>
  <div class="home-page-content my-business-info">
    <h3 class="mb-20">我的经营信息查询</h3>
    <Form ref="formData" :model="formData" :label-width="80">
      <Row :gutter="30">
        <Col span="6">
          <FormItem label="项目名称" prop="projectName">
            <Input v-model="formData.projectName" placeholder="请输入"></Input>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="信息类型" prop="infoType">
            <Select v-model="formData.infoType" placeholder="全部" clearable>
              <Option :value="value" v-for="(label, value) in EnumBusinessTypeStatus" :key="value">{{ label }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="产业标记" prop="industryAssigns">
            <Select v-model="formData.industryAssigns" placeholder="全部" multiple>
              <Option :value="it.name" v-for="(it, index) in industryAssignsList" :key="index">{{ it.name }}</Option>
            </Select>
          </FormItem>
        </Col>
      </Row>
      <Row :gutter="30">
        <Col span="6">
          <FormItem label="发布时间" prop="times">
            <DatePicker
              v-model="formData.times"
              format="yyyy/MM/dd"
              type="daterange"
              placeholder="请选择时间"
              style="width: 100%"
            ></DatePicker>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="审核状态" prop="auditStatus">
            <Select v-model="formData.auditStatus" placeholder="全部" clearable>
              <Option :value="value" v-for="(label, value) in EnumAuditStatus" :key="value">{{ label }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="接收状态" prop="acceptStatus">
            <Select v-model="formData.acceptStatus" placeholder="全部" clearable>
              <Option :value="value" v-for="(label, value) in EnumReceiveStatus" :key="value">{{ label }}</Option>
            </Select>
          </FormItem>
        </Col>

        <Col span="6" class="com-action-search-btn">
          <Button type="primary" icon="md-search" @click="handleSubmit('formData')">查询</Button>
          <BtnPlain type="primary" @click="handleReset('formData')">
            <Icon type="md-refresh" />
            <span>重置</span>
          </BtnPlain>
        </Col>
      </Row>
    </Form>
    <Table :columns="columns" :data="listData">
      <template slot-scope="{ row }" slot="location">
        <BtnText type="primary" @BtnClick="onViewLocation(row)">查看定位</BtnText>
      </template>
      <template slot-scope="{ row }" slot="auditStatus">
        <BtnPlain :type="row.auditStatus | getAuditStatus">{{ row.auditStatusName }}</BtnPlain>
      </template>
      <template slot-scope="{ row }" slot="acceptStatus">
        <BtnPlain :type="row.acceptStatus | getAcceptStatus">{{ row.acceptStatusName }}</BtnPlain>
      </template>
      <template slot-scope="{ row }" slot="view">
        <BtnText v-if="row.rootInformationEnum === 'Derivative'" type="primary" @BtnClick="onSourceInfo(row)">查看源信息</BtnText>
      </template>
      <template slot-scope="{ row }" slot="action">
        <BtnText type="primary" @BtnClick="onView(row,'view')">详情</BtnText>
        <BtnText v-if="showActionBtn('修改', row)" type="warning" @BtnClick="onEdit(row)">修改</BtnText>
        <BtnText v-if="showActionBtn('接收', row)" type="green" @BtnClick="onView(row,'receive')">接收</BtnText>
        <BtnText v-if="showActionBtn('反馈', row)" type="primary" @BtnClick="onView(row,'feedback')">反馈</BtnText>
        <BtnText v-if="showActionBtn('撤销', row)" type="warning" @BtnClick="onRevoke(row)">撤销</BtnText>
        <BtnText v-if="showActionBtn('删除', row)" type="warning" @BtnClick="onRemove(row)" >删除</BtnText>
      </template>
    </Table>
    <PageAtion
      v-if="formData.total"
      :total="formData.total"
      :size.sync="formData.size"
      :page.sync="formData.page"
      @pageSizeChange="pageSizeChange"
    />
    <SourceInfo v-model="modalValue" :parentId="tableParentId" />
    <ViewLocation v-model="modalValueLocation" :info="locationInfo" />
  </div>
</template>

<script>
import SourceInfo from "./common/sourceInfo.vue";
import ViewLocation from "./common/viewLocation.vue";
import {
  busiInfoGetPage,
  busiInfoCancelData,
  deleteDataMyBusiness,
} from "@/api/businessInformationManage.js";
import { getDictTreeByParentId } from "@/api/system.js";

export default {
  name: 'myBusinessInfo',
  components: { SourceInfo, ViewLocation },
  data () {
    return {
      tableParentId: '',
      formData: {
        projectName: '',
        auditStatus: '',
        acceptStatus: '',
        publishTimeStart: '',
        publishTimeEnd: '',
        times: [],
        infoType: '',
        industryAssigns: [],
        page: 1,
        size: 10,
        total: 10,
      },
      columns: [
        {
          title: '项目名称',
          key: 'projectName',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '信息类型',
          key: 'infoTypeName',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '省份',
          key: 'province',
          minWidth: 120,
        },
        {
          title: '城市',
          key: 'city',
          minWidth: 120,
        },
        {
          title: '产业标记',
          key: 'industryAssign',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '项目位置',
          slot: 'location',
          minWidth: 120,
        },
        {
          title: '业主方',
          key: 'ownerCompanyName',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '施工方',
          key: 'constructionName',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '预计产值规模(万元)',
          key: 'outputScale',
          minWidth: 160,
        },
        {
          title: '项目阶段',
          key: 'projectStageName',
          minWidth: 100,
        },
        {
          title: '项目备注',
          key: 'projectRemark',
          minWidth: 240,
          tooltip: true
        },
        {
          title: '推送目标企业',
          key: 'pushCompany',
          minWidth: 240,
          tooltip: true
        },
        {
          title: '发布人',
          key: 'publisher',
          minWidth: 120,
        },
        {
          title: '发布时间',
          key: 'publishTime',
          minWidth: 170,
        },
        {
          title: '审核状态',
          slot: 'auditStatus',
          minWidth: 160,
        },
        {
          title: '接受状态',
          slot: 'acceptStatus',
          minWidth: 160,
        },
        {
          title: '派生信息标签',
          slot: 'view',
          minWidth: 160,
        },
        {
          title: '操作',
          slot: 'action',
          width: 170,
          align: 'center',
          fixed: 'right'
        },
      ],
      listData: [],
      modalValue: false,
      modalValueLocation: false,
      // 审核状态
      EnumAuditStatus: {
        UnderReview: '审核中',
        Pass: '通过',
        NotPass: '驳回',
        CancelAudit: '已撤回',
      },
      // 接收状态
      EnumReceiveStatus: {
        UnReceive: '未接收',
        Receive: '已接收',
        SectionReceive: '部分接收',
        Rejection: '已拒绝',
      },
      EnumBusinessTypeStatus: {
        ProfessionRelevance: '产业链关联',
        AllUserBusiness: '全民经营',
        // ExternalStatement: '项目备案',
      },
      locationInfo: {},
      industryAssignsList: []
    };
  },
  async created () {
    this.init()
    this.industryAssignsList = await getDictTreeByParentId({ parentId: 'COMPANY_SERVICE' })
  },
  methods: {
    async init () {
      const request = {
        ...this.formData,
        publishTimeStart: this.formData.times[0],
        publishTimeEnd: this.formData.times[1],
      }
      console.log('request', request, this.formData);

      const { data, page, size, total } = await busiInfoGetPage(request)
      this.listData = data
      this.formData = { ...this.formData, ...{ page, size, total } }
    },
    handleReset (name) {
      this.$refs[name].resetFields();
      this.init()
    },
    handleSubmit (name) {
      this.init()
    },
    pageSizeChange () {
      this.init()
    },
    // 查看来源信息
    onSourceInfo (row) {
      this.modalValue = true
      this.tableParentId = row.parentId
    },
    // 详情
    onView (row, type) {
      const { busiInfoId } = row
      this.$router.push({ path: '/businessInformationDetails', query: { busiInfoId, type } })
    },
    // 修改
    onEdit (row) {
      this.$router.push({ path: '/publishBusinessInfo', query: { type: 'edit', busiInfoId: row.busiInfoId } })
    },

    //撤销
    async onRevoke ({ busiInfoId }) {
      this.$Modal.confirm({
        title: "温馨提示",
        content: '将撤销本次更改，请确认是否继续？',
        onOk: async () => {
          await busiInfoCancelData({ busiInfoId })
          this.$Message.success('撤销成功！');
          this.init()
        }
      })
    },

    //删除
    async onRemove({ busiInfoId }) {
      this.$Modal.confirm({
        title: "温馨提示",
        content: "将删除数据，请确认是否继续？",
        onOk: async () => {
          await deleteDataMyBusiness({ busiInfoId });
          this.$Message.success("删除成功！");
          this.init();
        },
      });
    },
    /**
     * @description 查看地点
     * @param row 
     */
    onViewLocation (row) {
      this.modalValueLocation = true
      this.locationInfo = row
    },
    /**
     * @description 显示按钮
     * @param type 
     * @param row 
     */
    async showActionBtn(type, row) {
      let flag = false;
      console.log(userInfo, userInfo, "userInfo");
      switch (type) {
        case "接收":
        case "反馈":
          flag = row.auditStatus === "Pass";
          break;
        case "修改":
          flag =
            row.auditStatus === "NotPass" || row.auditStatus === "CancelAudit";
          break;
        case "撤销":
          flag = row.auditStatus === "UnderReview";
          break;
        case "删除":
          let userInfo = await this.$store.dispatch("admin/db/get", {
            dbName: "sys",
            path: "user.info",
            defaultValue: "1.0.0",
            user: true,
          });
          flag = row.auditStatus === "CancelAudit" && row.publisherId == userInfo.userId;
          break;
      }
      return flag;
    },
  },
};
</script>

<style lang="less">
.my-business-info .badge-alone {
  border-radius: 3px;
  padding: 0;
  min-width: 15px;
  height: 15px;
  font-size: 11px;
  line-height: 13px;
}
.mb-20 {
  margin-bottom: 20px;
}
</style>

